package com.dzl.aboutUs;

import com.dzl.aboutUs.pojo.WelfareAboutUs;
import com.dzl.aboutUs.service.WelfareAboutUsService;
import com.dzl.base.controller.BaseController;
import com.dzl.constant.CommonConstants;
import com.dzl.util.EmptyUtils;
import com.dzl.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 关于我们(WelfareAboutUs)表控制层
 * @author caobucao
 * @since 2021-05-13 15:54:17
 */
@Api(value = "企业端-关于我们管理", tags = "企业端-关于我们管理")
@RestController
@RequestMapping("welfareAboutUs")
public class WelfareAboutUsController extends BaseController {

    @Autowired
    private WelfareAboutUsService welfareAboutUsService;

    /**
     * 根据企业查询关于我们
     * @date 2021/5/17 17:48
     * @author caobucao
     * @return com.dzl.aboutUs.entity.WelfareAboutUs 对象
     */
    @ApiOperation(value = "平台端-根据企业查询关于我们", notes = "平台端-根据企业查询关于我们")
    @GetMapping("getAboutUs")
    public JsonResult<WelfareAboutUs> getAboutUs() {
        WelfareAboutUs aboutUs=new WelfareAboutUs();
        aboutUs.setEnterpriseId(getAdminInfo().getEnterpriseId());
        return JsonResult.success(welfareAboutUsService.selectOne(aboutUs));

    }

    /**
     * 编辑关于我们
     * @date 2021/5/17 17:53
     * @author caobucao
     * @param welfareAboutUs 关于我们对象
     * @return com.dzl.util.JsonResult<java.lang.Integer>
     */
    @PostMapping("saveAboutUs")
    public JsonResult<Integer> saveAboutUs(@RequestBody WelfareAboutUs welfareAboutUs) {
        if(EmptyUtils.isEmpty(welfareAboutUs)) {
            return JsonResult.paramErrWithMsg("请编写关于我们");
        }
        welfareAboutUs.setUpdater(getAdminInfo().getId());
        welfareAboutUs.setUpdaterName(getAdminInfo().getUserName());
        welfareAboutUs.setUpdateTime(new Date());
        if(null==welfareAboutUs.getId()) {
            welfareAboutUs.setStatus(CommonConstants.YES);
            welfareAboutUs.setCreater(getAdminInfo().getId());
            welfareAboutUs.setCreaterName(getAdminInfo().getUserName());
            welfareAboutUs.setCreateTime(new Date());
            welfareAboutUs.setEnterpriseId(getAdminInfo().getEnterpriseId());
            welfareAboutUsService.insertSelective(welfareAboutUs);
        } else {
            welfareAboutUsService.updateByPrimaryKeySelective(welfareAboutUs);
        }
        return JsonResult.success();
    }

}
